//package com.example.e_comm.vehicle.config;
//
//import com.example.vehicle.exception.BusinessException;
//import com.example.vehicle.exception.ErrorResponse;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.http.HttpStatus;
//import org.springframework.validation.FieldError;
//import org.springframework.web.bind.MethodArgumentNotValidException;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseStatus;
//import org.springframework.web.bind.annotation.RestControllerAdvice;
//
//import java.util.List;
//import java.util.stream.Collectors;
//
//@Slf4j
//@RestControllerAdvice
//public class GlobalExceptionHandler {
//
//    @ExceptionHandler(BusinessException.class)
//    @ResponseStatus(HttpStatus.BAD_REQUEST)
//    public ErrorResponse handleBusinessException(BusinessException e) {
//        log.error("业务异常: {}", e.getMessage());
//        return new ErrorResponse("BUSINESS_ERROR", e.getMessage());
//    }
//
//    @ExceptionHandler(MethodArgumentNotValidException.class)
//    @ResponseStatus(HttpStatus.BAD_REQUEST)
//    public ErrorResponse handleValidationException(MethodArgumentNotValidException e) {
//        List<FieldError> fieldErrors = e.getBindingResult().getFieldErrors();
//        String errorMessage = fieldErrors.stream()
//                .map(error -> error.getField() + ": " + error.getDefaultMessage())
//                .collect(Collectors.joining("; "));
//        log.error("参数验证失败: {}", errorMessage);
//        return new ErrorResponse("VALIDATION_ERROR", errorMessage);
//    }
//
//    @ExceptionHandler(Exception.class)
//    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
//    public ErrorResponse handleException(Exception e) {
//        log.error("系统异常: ", e);
//        return new ErrorResponse("SYSTEM_ERROR", "系统繁忙，请稍后重试");
//    }
//}